
	var page=1;
	var pagenum=10;
	var fi=1
	
	var main=[[ //表头
		{if $Think.get.op}
		 {title: '',toolbar: '#choose',fixed: 'left'},
		 {else/}
		 {type:'checkbox', fixed: 'left'},
		 {/if}
		 {field:'name', width:200,title: '乘客姓名', templet: '#passenger_id', fixed: 'left'}
        ,{field: 'phone', title: '电话',  sort: true}
        ,{field: 'sex2', title: '性别'} 
        ,{field: 'is_check2', title: '角色'}
        ,{field: 'balance', title: '余额'}
        ,{field: 'company_name', title: '所属公司'}
        ,{field: 'unit_quota', title: '公司额度'}
        ,{field: 'personal_quota', title: '个人额度'}
        ,{field:'state2', title:'状态'}
        {if $Think.get.op}
         {else/}
        ,{ title: '操作',width:250, toolbar:'#operation',fixed: 'right'}
         {/if}
    ]];
    var data={};
    data.page=page;
    data.pagenum=pagenum;
    var where_json={};
    {if $Think.get.is_check}
		where_json.is_check=['in','{$Think.get.is_check}']
	{/if}
	
	{if $Think.get.name}
		where_json.name=['like','%{$Think.get.name}%']
	{/if}
	{if $Think.get.phone}
		where_json.phone=['like','%{$Think.get.phone}%']
	{/if}
	{if $Think.get.company_name}
		where_json.company_name=['like','%{$Think.get.company_name}%']
	{/if}
	
	data.where_json=JSON.stringify(where_json)
    ajaxdriver(data)
    function ajaxdriver(data) {
    	console.log(data)
    	Load()
    	ajax(api.passenger.list, data, 'post').done(function (res) {
    		res=passengerstate(res);
    		for(var di=0;di<res.data.length;di++){
    			if(res.data[di].balance){}else{
    				res.data[di].balance=0
    			}
    			if(res.data[di].unit_quota){}else{
    				res.data[di].unit_quota=0
    			}
    			if(res.data[di].personal_quota){}else{
    				res.data[di].personal_quota=0
    			}
    		}
    		Load(1)
    		if (res.code == 1) {
    			console.log(res)
    			res = driverstate(res)
    			var table = layui.table,
    				form = layui.form;
    			table.render({
    				elem: '#driver',
    				cellMinWidth: 80,
    				cols: main,
    				data: res.data,
    				limit: data.pagenum,
    				even: true
    			});
    			if (fi == 1) {
    				laypage.render({
    					elem: 'page',
    					count: res.count,
						layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip'],
						theme: '#1E9FFF',
    					jump: function (obj, first) {
    						if (!first) {
    							page = obj.curr
    							data.page = page
    							pagenum = obj.limit
    							data.pagenum = pagenum
    							ajaxdriver(data)
    						} else {

    						}
    					}
    				});
    				fi = 2
    			}
    			{if $Think.get.op}
					table.on('tool(driver)', function(obj) {
						var data1 = obj.data; //获得当前行数据
						var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
						var tr = obj.tr; //获得当前行 tr 的DOM对象
						if(layEvent === 'choose') {
							var index = parent.layer.getFrameIndex(window.name);
							console.log(data1)
							{if $Think.get.op=='seaech_orderer'}
							parent.$('.orderer_id').val(data1.passenger_id)
							parent.$('.orderer_name').val(data1.name)
							{else/}
								{if $Think.get.is_check}
								parent.$('.approval_id').val(data1.passenger_id)
								parent.$('.approval_name').val(data1.name)
								{else/}
								parent.$('.passenger_id').val(data1.passenger_id)
								parent.$('.passenger_name').val(data1.name)
								parent.$('.phone').val(data1.phone)
							{/if}
							{/if}
							
							parent.layer.close(index);
						}
					})
					{else/}
    			table.on('tool(driver)', function (obj) {
    				var data1 = obj.data; //获得当前行数据
    				var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
    				var tr = obj.tr; //获得当前行 tr 的DOM对象
    				if (layEvent === 'detail') { //查看

    					window.location.href = "{:url('/admin/driver/detail')}?driver_id=" + data1.driver_id
    				} else if (layEvent === 'del') { //删除
    					layer.confirm('是否删除', function (index) {
    						Load()
    						$.ajax({
    							method: "POST",
    							url: "{:url('/admin/driver/delete')}",
    							data: {
    								id: data1.driver_id
    							},
    							success: function (res) {
    								if (res.code == 1) {
    									ajaxdriver(data)
    									layer.close(index);
    									Load(1)

    								} else {
    									layer.close(index);
    									Load(1)
    									Err(res.msg ? res.msg : '操作失败，稍候再试');
    								}

    							},
    							error: function () {
    								Load(1)
    								Err('请求失败')
    							}
    						});
    						layer.close(index);
    					});
    				} else if (layEvent === 'edit') { //编辑
    					//do something
    					window.location.href = " {:url('/html/system/passenger_add')}?passenger_id=" + data1.passenger_id + "&page=" + page
    					//同步更新缓存对应的值

    				} else if (layEvent === 'relevance') { //编辑
    					//do something
    					window.location.href = " {:url('/admin/driver/relevance')}?driver_id=" + data1.driver_id + "&page=" + page
    					//同步更新缓存对应的值
    					relevance
    				} else if (layEvent === 'forbidden') {
    					layer.confirm('是否禁用', function (index) {
    						Load()
    						$.ajax({
    							method: "POST",
    							url: "{:url('/admin/driver/state')}",
    							data: {
    								id: data1.driver_id,
    								state: 9
    							},
    							success: function (res) {
    								if (res.code == 1) {
    									ajaxdriver(data)
    									layer.close(index);
    									Load(1)

    								} else {
    									layer.close(index);
    									Load(1)
    									Err(res.msg ? res.msg : '操作失败，稍候再试');
    								}

    							},
    							error: function () {
    								Load(1)
    								Err('请求失败')
    							}
    						});
    						layer.close(index);
    					});
    				} else if (layEvent === 'startusing') {
    					layer.confirm('是否启用', function (index) {
    						Load()
    						$.ajax({
    							method: "POST",
    							url: "{:url('/admin/driver/state')}",
    							data: {
    								id: data1.driver_id,
    								state: 1
    							},
    							success: function (res) {
    								if (res.code == 1) {
    									ajaxdriver(data)
    									layer.close(index);
    									Load(1)

    								} else {
    									layer.close(index);
    									Load(1)
    									Err(res.msg ? res.msg : '操作失败，稍候再试');
    								}

    							},
    							error: function () {
    								Load(1)
    								Err('请求失败')
    							}
    						});
    						layer.close(index);
    					});
    				}
    			});
    			{/if}
    			//删除多个
    			$(".delete-multiple").on('click', function () {
    				var driver_ids = '';
    				var checkStatus = table.checkStatus('driver'); //test即为基础参数id对应的值
    				console.log(checkStatus.data) //获取选中行的数据
    				console.log(checkStatus.data.length) //获取选中行数量，可作为是否有选中行的条件
					console.log(checkStatus.isAll) //表格是否全选
					if(checkStatus.data.length){
    				for (var dei = 0; dei < checkStatus.data.length; dei++) {
    					if (dei == 0) {
    						driver_ids += checkStatus.data[dei].driver_id
    					} else {
    						driver_ids += ("," + checkStatus.data[dei].driver_id)
    					}
    				}
    				console.log(driver_ids)
    				layer.open({
    					type: 1,
    					title: false,
    					id: "delete",
    					content: '<div style="padding: 20px 100px;">是否删除</div>',
    					btn: ['确定', '取消'],
    					btnAlign: 'c' //按钮居中
    						,
    					shade: 0 //不显示遮罩
    						,
    					yes: function () {
    						var deleteload = layer.load(1, {
    							shade: [0.1, '#fff'] //0.1透明度的白色背景
    						});
    						$.ajax({
    							method: "POST",
    							url: url.delete,
    							data: {
    								driver_ids: driver_ids
    							},
    							success: function (res) {
    								console.log(res)
    								if (res.code == 1) {
    									layer.close(deleteload);
    									layer.closeAll();
    									Msg('删除成功')
    									ajaxdriver(data)
    								} else {
    									layer.close(deleteload);
    									Err(res.msg ? res.msg : '操作失败，稍候再试');
    								}

    							}
    						});

    					},
    					btn2: function () {
    						layer.closeAll();
    					}
					});
				}else{
					Err('未有选择项')
				}
    			});

    		} else {
    			Err(res.msg)
    		}
    	}).fail(function (err) {
    		Err('请求失败')
    	});

    }
	
	//添加
	$('.add').on('click',function(){
		window.location.href='{:url("/html/system/passenger_add")}'
	});
	

	

